|
2 | 2 |
|
3 | 3 | var defineProperties = require('define-properties');
|
4 | 4 | var test = require('tape');
|
| 5 | +var forEach = require('for-each'); |
| 6 | +var getProto = require('es-abstract/helpers/getProto'); |
5 | 7 |
|
6 | 8 | var index = require('../Uint8Array.fromHex');
|
7 | 9 | var impl = require('../Uint8Array.fromHex/implementation');
|
@@ -52,6 +54,61 @@ module.exports = {
|
52 | 54 | 'hex (' + hex + ') produces expected bytes (' + expected.join(', ') + ')'
|
53 | 55 | );
|
54 | 56 |
|
| 57 | + var illegal = [ |
| 58 | + 'a.a', |
| 59 | + 'aa^', |
| 60 | + 'a a', |
| 61 | + 'a\ta', |
| 62 | + 'a\x0Aa', |
| 63 | + 'a\x0Ca', |
| 64 | + 'a\x0Da', |
| 65 | + 'a\u00A0a', // nbsp |
| 66 | + 'a\u2009a', // thin space |
| 67 | + 'a\u2028a' // line separator |
| 68 | + ]; |
| 69 | + forEach(illegal, function (value) { |
| 70 | + st['throws']( |
| 71 | + function () { method(value); }, |
| 72 | + SyntaxError |
| 73 | + ); |
| 74 | + }); |
| 75 | + |
| 76 | + var cases = [ |
| 77 | + ['', []], |
| 78 | + ['66', [102]], |
| 79 | + ['666f', [102, 111]], |
| 80 | + ['666F', [102, 111]], |
| 81 | + ['666f6f', [102, 111, 111]], |
| 82 | + ['666F6f', [102, 111, 111]], |
| 83 | + ['666f6f62', [102, 111, 111, 98]], |
| 84 | + ['666f6f6261', [102, 111, 111, 98, 97]], |
| 85 | + ['666f6f626172', [102, 111, 111, 98, 97, 114]] |
| 86 | + ]; |
| 87 | + forEach(cases, function (pair) { |
| 88 | + var arr = method(pair[0]); |
| 89 | + st.equal(getProto(arr), Uint8Array.prototype, 'decoding ' + pair[0]); |
| 90 | + st.deepEqual(arr, new Uint8Array(pair[1]), 'decoding ' + pair[0]); |
| 91 | + }); |
| 92 | + |
| 93 | + st.test('test262: test/built-ins/Uint8Array/fromHex/string-coercion.js', function (s2t) { |
| 94 | + var throwyToString = {}; |
| 95 | + var results = s2t.intercept( |
| 96 | + throwyToString, |
| 97 | + 'toString', |
| 98 | + { |
| 99 | + value: function () { throw new EvalError('toString called'); } |
| 100 | + } |
| 101 | + ); |
| 102 | + |
| 103 | + s2t['throws']( |
| 104 | + function () { method(throwyToString); }, |
| 105 | + TypeError |
| 106 | + ); |
| 107 | + s2t.deepEqual(results(), []); |
| 108 | + |
| 109 | + s2t.end(); |
| 110 | + }); |
| 111 | + |
55 | 112 | st.end();
|
56 | 113 | });
|
57 | 114 | },
|
|
0 commit comments